package com.woniuxy.sale.controller;

import com.woniuxy.commons.annotations.RequirePermission;
import com.woniuxy.commons.entity.sale.PackingMsg;
import com.woniuxy.commons.entity.sale.dto.ChooseProduceMsgDto;
import com.woniuxy.commons.result.Result;
import com.woniuxy.sale.service.PackingMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: CHL  <br/>
 * @TODO: 打包信息controller
 * Date: 2022/4/21:10:50  <br/>
 * Description:
 */
@RestController
@RequestMapping("/sale/packingMsg")
@Api(tags = "打包信息controller")
public class PackingMsgController {
    @Resource
    PackingMsgService packingMsgService;

    @RequirePermission("addPackingList")
    @ApiOperation(value = "新增打包信息")
    @PostMapping("/insert")
    public Result insertPackingMsg(@RequestBody PackingMsg packingMsg){
        if (packingMsg!=null || packingMsgService.insert(packingMsg)>0) {
            return Result.ok("插入成功");
        }
        return Result.fail("插入失败");
    }

    @RequirePermission("addPackingList")
    @ApiOperation(value = "测试更新状态方法")
    @GetMapping("/testUpdatePackingStatus/{psId}")
    public Result  testUpdatePackingStatus(@PathVariable("psId") Integer psId){
        return packingMsgService.updatePackingStatus(psId);
    }

    @RequirePermission("addPackingList")
    @ApiOperation(value = "根据大的打包单编号查询分包列表")
    @GetMapping ("/selectPMByPackingNum/{packingNum}")
    public Result selectPackingMsg(@PathVariable(value = "packingNum") String packingNum){
        if (packingNum!=null) {
            List<PackingMsg> packingMsgs = packingMsgService.selectPackingMsgByPackingNum(packingNum);
            return Result.ok(packingMsgs);
        }
        return Result.fail("插入失败");
    }

    @RequirePermission("addPackingList")
    @ApiOperation(value = "根据分包单的id查询分包下的产品")
    @GetMapping ("/selectProductByProductId/{id}")
    public Result selectProductByProductId(@PathVariable(value = "id") int id){
        if (id!=0) {
            List<ChooseProduceMsgDto> products = packingMsgService.selectProductByProductId(id);
            return Result.ok(products);
        }
        return Result.fail("分包产品查询失败");
    }
}
